home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / smaltalk / gnu_st.lha / gnu_st / smalltalk-1.1.1 / stix / GC.st < prev    next >
Text File  |  1991-09-12  |  5KB  |  183 lines

  1. "======================================================================
  2. |
  3. | Copyright (C) 1990, 1991 Free Software Foundation, Inc.
  4. | Written by Steve Byrne.
  5. |
  6. | This file is part of GNU Smalltalk.
  7. |
  8. | GNU Smalltalk is free software; you can redistribute it and/or modify it
  9. | under the terms of the GNU General Public License as published by the Free
  10. | Software Foundation; either version 1, or (at your option) any later version.
  11. | GNU Smalltalk is distributed in the hope that it will be useful, but WITHOUT
  12. | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  13. | FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  14. | details.
  15. | You should have received a copy of the GNU General Public License along with
  16. | GNU Smalltalk; see the file COPYING.  If not, write to the Free Software
  17. | Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  
  18. |
  19.  ======================================================================"
  20.  
  21.  
  22. "
  23. |     Change Log
  24. | ============================================================================
  25. | Author       Date       Change 
  26. | sbyrne     24 May 90      created.
  27. |
  28. "
  29.  
  30.  
  31.  
  32. !GC class methodsFor: 'instance creation'!
  33.  
  34. new: aDisplay drawable: aDrawable
  35.     ^super new init: aDisplay drawable: aDrawable
  36. !!
  37.  
  38. !GC methodsFor: 'X hacking'!
  39.  
  40. changeGC: aBlock
  41.     | packet gc |
  42.     
  43.     packet _ XGCAttrPacket command: 56.
  44.  
  45.     packet long: self id.
  46.     aBlock notNil
  47.     ifTrue: [ aBlock value: packet ]
  48.     ifFalse: [ packet noBits ].
  49.     display socket bytes: packet done.
  50. !
  51.  
  52. polyPoint: pointsVec coordMode: coordMode
  53.     | packet |
  54.     
  55.     packet _ XPacket command: 64 
  56.              aux: (X map: coordMode into: #(Origin Previous)).
  57.     packet long: drawable id; long: self id.
  58.     pointsVec do: [ :point | packet point: point ].
  59.     display socket bytes: packet done
  60. !    
  61.  
  62. polyLine: pointsVec coordMode: coordMode 
  63.     | packet |
  64.     
  65.     packet _ XPacket command: 65 
  66.              aux: (X map: coordMode into: #(Origin Previous)).
  67.     packet long: drawable id; long: self id.
  68.     pointsVec do: [ :point | packet point: point ].
  69.     display socket bytes: packet done
  70. !    
  71.  
  72. polyLine: aPoint to: otherPoint coordMode:  coordMode
  73.     | packet |
  74.     
  75.     self polyLine: (Array with: aPoint with: otherPoint) 
  76.       coordMode: coordMode
  77. !
  78.  
  79.  
  80. polySegment: segmentVec
  81.     | packet |
  82.  
  83.     packet _ XPacket command: 66. "segments are currently implemented using rectangles"
  84.     packet long: drawable id; long: self id.
  85.     segmentVec do: [ :seg | packet rectangle: seg ].
  86.     display socket bytes: packet done
  87. !
  88.  
  89.  
  90. polyRectangle: rectangleVec
  91.     | packet |    
  92.  
  93.     (rectangleVec isMemberOf: Rectangle) "ugh"
  94.     ifTrue: [ rectangleVec _ Array with: rectangleVec ].
  95.  
  96.     packet _ XPacket command: 67.
  97.     packet long: drawable id; long: self id.
  98.     rectangleVec do: [ :rect | packet point: rect origin.
  99.                    packet point: rect extent ].
  100.     display socket bytes: packet done
  101. !
  102.     
  103. polyArc: arcs
  104.     | packet |    
  105.  
  106.     packet _ XPacket command: 68.
  107.     packet long: drawable id; long: self id.
  108.     arcs do: [ :arc | packet arc: arc ].
  109.     display socket bytes: packet done
  110. !
  111.  
  112. "fillPoly"
  113.  
  114. polyFillRectangle: rectangles
  115.     | packet |
  116.  
  117.     packet _ XPacket command: 70.
  118.     packet long: drawable id; long: self id.
  119.     rectangles do: [ :rect | packet rectangle: rect ].
  120.     display socket bytes: packet done
  121. !    
  122.  
  123.  
  124. " ... "
  125.  
  126. polyText8: textItems x: x y: y
  127.     | packet |
  128.     
  129.     packet _ XPacket command: 74.
  130.     packet long: drawable id; long: self id; word: x; word: y.
  131.     textItems do: [ :textItem | packet textItem: textItem ].
  132.     display socket bytes: packet done
  133. !!
  134.  
  135.  
  136. !GC methodsFor: 'accessing'!
  137.  
  138. id
  139.     ^id
  140. !!
  141.  
  142. !GC methodsFor: 'example class'!
  143.  
  144.  
  145. drawExampleImage: button
  146.     self polyText8: (Array with: (TextItem onString: 'Welcome to ')
  147.              with: (TextItem onString: Version ))
  148.        x: 50 y: 30.
  149.  
  150.     self polyLine: 20@20 to: 40@40 coordMode: #Origin.
  151.     self polyLine: 40@20 to: 20@40 coordMode: #Origin.
  152.     
  153.     self polyRectangle: (Array with: (10 @ 10 corner: (400 - 20) @ (200 - 20))). 
  154.     self drawExampleButton: button.
  155. "    self polyFillRectangle: (Array with:  (10 @ 10 corner: 50 @ 50))."
  156.     self polyArc: (Array with: (Arc new: 10 @ 10 size: 40 @ 40 angles: (90*64) @ (180*64))).
  157.     self polyArc: (Array with: (Arc new: 10 @ 50 size: 40 @ 40 angles: (270*64) @ (180*64)))
  158. !
  159.  
  160.  
  161. drawExampleButton: button
  162.     | textStart |
  163.     self polyRectangle: (Array with: button). 
  164.     textStart _ button leftCenter.
  165.     self polyText8: (Array with: (TextItem onString: 'Click here to exit'))
  166.      x: textStart x + 10 y: textStart y
  167. !!
  168.  
  169.  
  170. !GC methodsFor: 'private'!
  171.  
  172. init: aDisplay drawable: aDrawable
  173.     display _ aDisplay.
  174.     drawable _ aDrawable.
  175.     id _ display nextId.
  176.     Registry at: id put: self
  177.     
  178. !!
  179.  
  180.  
  181.